/*
 *https://www.luogu.com.cn/problem/P1162
 *洛谷P1162. 填涂颜色
 *medium 吴朝泽 2024.12.2
 *BFS广度优先搜索
*/

#include<bits/stdc++.h>
using namespace std;
int xx[] = {0, -1, 0, 1};    //上下左右可到达的四个方向
int yy[] = {1, 0, -1, 0};
int mp[35][35];
bool vis[35][35];

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			cin >> mp[i][j];
		}
	}
	queue<int> x;
	queue<int> y;
	x.push(0);     //取最左上角那个元素为队首，可在输入的矩阵外再加一层 0
	y.push(0);
	vis[0][0] = 1;
	while(!x.empty())
	{
		for (int i = 0; i < 4; ++i)
		{
			int dx = x.front() + xx[i];
			int dy = y.front() + yy[i];
			if (dx >= 0 && dx <= n + 1 && dy >= 0 && dy <= n + 1 && mp[dx][dy] == 0 && !vis[dx][dy])
			{
				//符合条件就入队，并标记 vis 数组为 1
				x.push(dx);
				y.push(dy);
				vis[dx][dy] = 1;
			}
		}
		x.pop();
		y.pop();
	}
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			if (mp[i][j] == 0 && vis[i][j] == 0)
				cout << 2;
			else
				cout << mp[i][j];
			cout << " ";   //记得输出有空格
		}
		cout << endl;
	}
}